import { http } from '/@/utils/http';
import { ContentTypeEnum } from '/@/enums/httpEnum';
import type {
  SpColumnPageParams,
  SpColumnPageResultModel,
  SpColumnListParams,
  SpColumnListResultModel,
  AddSpColumnParams,
  AddSpColumnResultModel,
  SpColumnRecord,
  SpColumnInfoParams,
  SpColumnFollowParams,
} from './model/columnModel';

/**
 * 获取专栏分页
 * @param params SpColumnPageParams
 * @returns SpColumnPageResultModel
 */
export function querySpColumnPage(params: SpColumnPageParams) {
  return http.post<SpColumnPageResultModel>({
    url: '/api/web/article/sp_column/page',
    params,
  });
}

/**
 * 获取专栏列表
 * @param
 * @returns SpColumnListResultModel
 */
export function querySpColumnList(params: SpColumnListParams) {
  return http.post<SpColumnListResultModel>({
    url: '/api/web/article/sp_column/list',
    params,
  });
}

/**
 * 获取专栏信息
 * @param id number
 * @returns SpColumnRecord
 */
export function querySpColumnInfo(id: number) {
  return http.get<SpColumnRecord>({
    url: '/api/web/article/sp_column/info',
    params: {
      id,
    },
  });
}

/**
 * 新增专栏
 * @param params AddSpColumnParams
 * @returns AddSpColumnResultModel
 */
export function addSpColumn(params: AddSpColumnParams) {
  return http.post<AddSpColumnResultModel>({
    url: '/api/web/article/sp_column/add',
    params,
  });
}

/**
 * 修改专栏
 * @param params SpColumnRecord
 * @returns AddSpColumnResultModel
 */
export function updateSpColumn(params: SpColumnRecord) {
  return http.post<AddSpColumnResultModel>({
    url: '/api/web/article/sp_column/update',
    headers: {
      'Content-Type': ContentTypeEnum.JSON,
    },
    params,
  });
}

/**
 * 删除专栏
 * @param id number
 * @returns
 */
export function deleteSpColumn(id: number) {
  return http.post({
    url: '/api/web/article/sp_column/delete',
    params: {
      ids: [id],
    },
  });
}

/**
 * 获取专栏信息 用户
 * @param id number
 * @returns SpColumnRecord
 */
export function appSpColumnInfo(params: SpColumnInfoParams) {
  return http.post<SpColumnRecord>({
    url: '/api/app/article/sp_column/sp_info',
    params,
  });
}

/** 将文章添加至专栏
 * @param id number
 * @returns
 */
export function operateArticleToSpColumn(ids: number[], new_sp_column_id: number) {
  return http.post({
    url: '/api/web/article/article/updateSp_column',
    params: {
      ids,
      new_sp_column_id,
      old_sp_column_id: 0,
    },
  });
}

/** 取消收录
 * @param id number
 * @returns
 */
export function deleteArticleFromSpColumn(ids: number[], old_sp_column_id: number) {
  return http.post({
    url: '/api/web/article/article/updateSp_column',
    params: {
      ids,
      new_sp_column_id: 0,
      old_sp_column_id,
    },
  });
}

/** 将文章移动至其他专栏
 * @param id number
 * @returns
 */
export function addArticleToSpColumn(ids: number[], new_sp_column_id: number) {
  return http.post({
    url: '/api/web/article/article/updateSp_column',
    params: {
      ids,
      new_sp_column_id,
      old_sp_column_id: 0,
    },
  });
}

/** 将文章移动至其他专栏
 * @param id number
 * @returns
 */
export function addArticleToOtherSpColumn(
  ids: number[],
  new_sp_column_id: number,
  old_sp_column_id: number,
) {
  return http.post({
    url: '/api/web/article/article/updateSp_column',
    params: {
      ids,
      new_sp_column_id,
      old_sp_column_id,
    },
  });
}

/** 文章排序变化
 * @param id number
 * @returns
 */
export function changeArticleIndexOnSpColumn(id: number, index: number, sp_column_id: number) {
  return http.post({
    url: '/api/web/article/article/updateIndexSp_column',
    params: {
      id,
      index,
      sp_column_id,
    },
  });
}

export function changeSubscribe(
  sp_column_id: number | undefined,
  is_subscribe: boolean | string | undefined,
) {
  return http.post({
    url: '/api/web/article/sp_column/subscribe',
    params: {
      sp_column_id,
      is_subscribe,
    },
  });
}
// 专栏
export function queryFollowSpColumnPage(params: SpColumnFollowParams) {
  return http.post<SpColumnPageResultModel>({
    url: '/api/web/article/sp_column/page',
    data: params,
  });
}
//关注的专栏
export function querySubscribe_page() {
  return http.post<SpColumnPageResultModel>({
    url: '/api/web/article/sp_column/subscribe_page',
  });
}
